home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / meminit.arc / MEMINIT.ASM next >
Assembly Source File  |  1980-01-01  |  8KB  |  248 lines

  1. page 60,132
  2. title 'MEMINIT - Obtain all available user memory'
  3. subttl 'Version 1.0 October, 1983'
  4.  
  5. stack SEGMENT para stack 'STACK'
  6.       db 16 dup('stack   ')
  7. stack ENDS
  8.  
  9. data SEGMENT at 40H                ; DOS data segment in low memory
  10.          org 13H
  11.          memory_size dw            ; total memory size (K bytes)
  12.          io_ram_size dw            ; memory in I/O channel (K bytes)
  13. data ENDS
  14.  
  15. code SEGMENT byte
  16.  
  17.          assume cs:code,ds:code,ss:stack
  18.  
  19.          original_memory_size  dw ?     ;
  20.          original_io_memory    dw ?     ; all sizes stored in 'K' bytes
  21.          additional_memory     dw ?     ;
  22.          starting_memory_block dw ?     ; location of program's PSP
  23.          command_proc_PSP      dw ?     ; location of command's PSP
  24.                                         ; (PSP=program segment prefix)
  25.  
  26.          crlf      db 10,13,'$'
  27.          msg1      db 'Original memory used:'
  28.          msg1data  db '       K bytes$'
  29.          msg2      db '  Total memory added:'
  30.          msg2data  db '       K bytes$'
  31.          msg3      db '        Total memory:'
  32.          msg3data  db '       K bytes$'
  33.  
  34.  
  35.          heading    db 10,13,'MEMINIT - Version 1.00',10,13
  36.                     db 10,13,'$'
  37.  
  38. .RADIX 16
  39.          dosfunction MACRO function_number
  40.              mov  ah,function_number
  41.              int  21
  42.          endm
  43.  
  44.          print MACRO msg,msgdata
  45.              mov  bx,offset msgdata
  46.              call convert_to_ascii
  47.              mov  dx,offset msg
  48.              dosfunction 9
  49.              mov  dx,offset crlf
  50.              dosfunction 9
  51.          endm
  52.  
  53.  
  54.    convert_to_ascii PROC far
  55.  ; -------------------------
  56.  
  57.                  ; convert_to_ascii converts a binary number
  58.                  ; in AX to ascii display characters
  59.  
  60.          push  dx            ; save register values
  61.          push  si
  62.          mov   cx,6          ; initialize destination with spaces
  63.  
  64.    fill_buff:
  65.          mov  byte ptr [bx],' '
  66.          inc bx
  67.          loop fill_buff
  68.          mov si,0A
  69.  
  70.   do_divide:
  71.          sub  dx,dx
  72.          div  si                  ; divide AX by 10
  73.          add  dx,'0'              ; convert remainder to ascii digit
  74.          dec  bx
  75.          mov  [bx],dl             ; store this char in the string
  76.          inc  cx                  ; count converted character
  77.          or   ax,ax               ; all done?
  78.          jnz  do_divide           ;   no: get next digit
  79.  
  80.          pop  si                  ; restore registers
  81.          pop  dx
  82.          ret                      ; and exit
  83.  
  84.  convert_to_ascii ENDP
  85.  
  86.  update_memory_control_words PROC far
  87. ;-----------------------------------
  88.  
  89.          assume cs:code,ds:data,ss:stack
  90.  
  91.          push es
  92.          push ds
  93.          mov  ax,data                  ; Set up DS to reference DOS
  94.          mov  ds,ax                    ;    variables in low memory
  95.          mov  ax,starting_memory_block
  96.          dec  ax                       ; AX points to memory control block
  97.                                        ;    starting at that spot, look for
  98.                                        ;    the end of the memory links
  99.                                        ;    ( byte zero = 'Z' )
  100.  find_ending_link:
  101.  
  102.          mov  es,ax                    ; set up address of mem control blk
  103.          cmp  byte ptr es:[0],5AH      ; Is this the ending link?
  104.          jz   found_the_link
  105.          add  ax,es:[3]                ; link to next area
  106.          inc  ax
  107.          jmp  find_ending_link
  108.  
  109.  found_the_link:                       ; now update length field of this
  110.                                        ; last mem control block to
  111.                                        ; include the additional memory
  112.          mov  bx,memory_size
  113.          mov  cl,6
  114.          shl  bx,cl                    ; convert to K bytes
  115.          sub  bx,ax
  116.          dec  bx
  117.          mov  es:[3],bx
  118.  
  119.          pop  ds                       ; restore registers
  120.          pop  es
  121.          clc                           ; indicate normal return (no error)
  122.          ret
  123.  
  124.  update_memory_control_words ENDP
  125.  
  126.  
  127.  memory_size_initialize PROC far
  128. ;-------------------------------
  129.  
  130.      assume ds:code,cs:code,es:data,ss:stack
  131.  
  132.         mov  cs:starting_memory_block,ds
  133.         push ds
  134.         sub  ax,ax
  135.         push ax
  136.         mov  ax,code
  137.         mov  ds,ax
  138.         mov  dx,es:[0C]                ; COMMAND's program segment prefix
  139.         mov  command_proc_PSP,dx       ;   which we will use to fix up
  140.                                        ;   DOS release 1.1
  141.  
  142.         mov  dx,offset heading         ; put out introductory heading
  143.         dosfunction 9
  144.  
  145.  
  146.         mov  bx,data                   ; get ROM-initialized
  147.         mov  es,bx                     ;    memory size
  148.         mov  ax,memory_size            ;    specifications
  149.         mov  original_memory_size,ax
  150.         mov  bx,io_ram_size
  151.         mov  original_io_memory,bx
  152.         mov  cl,6
  153.         shl  ax,cl                     ; convert from K bytes
  154.         mov  bx,0
  155.  
  156.  memory_loop:
  157.  
  158.         cmp  ax,0A000                  ; check if greater than
  159.         je   initialize_memory         ;    640K ..if so then end
  160.  
  161.         mov  ds,ax
  162.         mov  [bx],ax                   ; write segment # into byte
  163.         mov  cx,[bx]                   ; read segment # from byte
  164.         cmp  ax,cx                     ; if equal..memory exists
  165.         jne  initialize_memory         ;    else no more user memory
  166.         mov  ax,ds
  167.         add  ax,400                    ;  increment segment # by 16K
  168.         jmp  memory_loop               ;    and try some more
  169.  
  170.  initialize_memory:                    ; write data into the memory so that
  171.                                        ;  parity errors do not occur upon
  172.                                        ;  access of new memory
  173.  
  174.         mov  bx,memory_size
  175.         mov  cl,6
  176.         shl  bx,cl
  177.  
  178.         push ax                        ; save the value for AX containing
  179.         pop  dx                        ; the new top of memory.
  180.         mov  ax,0                      ;
  181.         cld                            ; set direction=forward
  182.  
  183.  store_initial_value:
  184.  
  185.         cmp  bx,dx
  186.         je   end_of_user_memory        ; go through newly allocated mem
  187.         mov  es,bx                     ; and write a pattern of X'0000'
  188.         mov  cx,03fff                  ; into each word.   This will protect
  189.         mov  di,0                      ; against a fatal parity error later
  190.         rep  stosw                     ; when mem is read without being
  191.         add  bx,400                    ; written.(Done 16K bytes at a time.)
  192.         jmp  store_initial_value
  193.  
  194.  end_of_user_memory:
  195.  
  196.         push dx                        ; restore the value for ax
  197.         pop  ax
  198.  
  199.         mov  cl,6                      ; convert from bytes to
  200.         shr  ax,cl                     ;   K bytes
  201.         mov  bx,code                   ; calculate changed memory
  202.         mov  ds,bx                     ;   sizes and ..
  203.         mov  bx,data
  204.         mov  es,bx
  205.         mov  memory_size,ax            ;   store back ..
  206.         sub  ax,original_memory_size   ;   into DOS variables
  207.         mov  additional_memory,ax
  208.         add  ax,original_io_memory
  209.         mov  io_ram_size,ax
  210.  
  211.         dosfunction 30                 ; check DOS version
  212.         cmp  al,00
  213.         je   modify_dos1               ; pre 2.0 DOS...handle special
  214.  
  215.         call update_memory_control_words         ;  routine for DOS 2.0
  216.  
  217.         jmp  display_results
  218.  
  219.  modify_DOS1:
  220.  
  221.         push ds
  222.         mov  dx,command_proc_PSP       ; get ready to store new
  223.         mov  ds,dx                     ; memory size in COMMAND's
  224.         mov  dx,memory_size            ; stored variable.
  225.         mov  cl,6
  226.         shl  dx,cl
  227.         mov  ds:[452],dx               ; location of memory size on
  228.         pop  ds                        ;  DOS release 1.1
  229.  
  230.  display_results:
  231.  
  232.         mov  ax,original_memory_size
  233.         print  msg1,msg1data
  234.  
  235.         mov  ax,additional_memory
  236.         print  msg2,msg2data
  237.  
  238.         mov  ax,memory_size
  239.         print  msg3,msg3data
  240.  
  241.  exit:
  242.         ret
  243.  
  244.  memory_size_initialize ENDP
  245.  
  246. code ENDS
  247.  
  248. END memory_size_initialize